/*
  (C) 2007 
  @author Michael Ocean

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

package sxe.core;

import snobject.snObject;
import snobject.snObjectArgList;
import snobject.snString;
import step.EvaluationFailure;
import step.FunctionWrapper;


public class debugtime extends FunctionWrapper {	
	
	public static long values[] = null;
	
	public snObject Call(snObjectArgList arg) throws EvaluationFailure {
		snString time = null;
		
		//long l = System.nanoTime();
		long l = System.currentTimeMillis();;
		time = new snString(String.valueOf(l));
		if(values==null){
			values = new long[1];
			values[0] = l;
		}
		else{
			long nvalues[] = new long[values.length + 1];
			System.arraycopy(values, 0, nvalues, 0, values.length);
			nvalues[values.length] = l;
			values = nvalues;
		}
		
		return time;
	}
	
	public static void ShowHistory(){
		int i;
		for(i=0;i<values.length;i++)
			System.out.println("values[" + i + "] = (" + values[i] + ") milliseconds");
		
		System.out.println("First to last was " + (values[i-1] - values[0]) + " milliseconds");
		//System.out.println("               or " + (values[i-1] - values[0])/1000000 + " milliseconds");
	}
}
